import React ,{useEffect}from "react";
import { Route, Routes, Navigate, useLocation } from "react-router-dom";
import NotFound from "../pages/NotFound";
import Login from "../pages/LoginPage";
import Layout from "../pages/Layout";
import { useSelector, useDispatch } from "react-redux";
import {isLogin} from '@u'

export default function AuthRoutes() {
    const routes =useSelector(state => state.user.autoRoutes)
    const location = useLocation()
    const dispatch = useDispatch()
    useEffect(() => {
// dispatch(shouldAutoApps())
    }, {location})
    return (
        <Routes>
           
            <Route path="/" element = {
                isLogin()?<Layout/>:<Navigate to='/login' />
            }>
            {
                routes.map((el) => {
                    return (
                        <Route key={el.path} path= {el.path} element = {<el.element/>}/> 
                    )
                })
            }
            <Route path="/" element = {<Navigate to = "/dashBoard" replace/>}/>
            </Route>
            <Route path="/login" element = {<Login/>}/>
            <Route path="*" element = {<NotFound/>}/>
        </Routes>
    )
}